#include<iostream>
using namespace std;
int main()
{
	int A, B, n;
	while (cin >> A >> B >> n)
	{
		if (!A && !B && !n)
		{
			break;
		}
		int arr[50];
		arr[1] = 1;
		arr[2] = 1;
		for (int i = 3; i <= 49; i++)
		{
			arr[i] = (A * arr[i - 1] + B * arr[i - 2]) % 7;
		}
		cout << arr[n % 49] << endl;
	}
	return 0;
}